<template>
    <div class="app-radio" :class="{checked: isChecked}" @click="toggle">
        <div class="check-icon"></div>
        <div class="label">{{label}}</div>
    </div>
</template>

<script>
    export default {
        name: "AppRadio",
        data() {
            return {

            };
        },
        model: {
            prop: 'checked',
            event: 'change'
        },
        props: {
            value: {
                default: '',
                required: true
            },
            checked: {
                default: ''
            },
            label: {
                default: '',
                type: String,
                required: true
            }
        },
        computed: {
            isChecked() {
                return this.checked === this.value;
            }
        },
        methods: {
            toggle() {
                if (this.checked !== this.value) {
                    this.$emit('change', this.value);
                }
            }
        }
    }
</script>

<style lang="scss" scoped>
    .app-radio {
        display: inline-block;
        &.checked {
            .check-icon {
                &:after {
                    background: #fff;
                    content: '\20';
                    width: 8/3.75+vw;
                    height: 8/3.75+vw;
                    border-radius: 10/3.75+vw;
                    position: absolute;
                    left: 4/3.75+vw;
                    top: 4/3.75+vw;
                }
            }
            .label {
                color: #fff;
            }
        }
        .check-icon {
            display: inline-block;
            width: 16/3.75+vw;
            height: 16/3.75+vw;
            border-radius: 16/3.75+vw;
            background: #C8292E;
            position: relative;
            vertical-align: middle;
        }
        .label {
            display: inline-block;
            margin-left: 5/3.75+vw;
            color: #dedede;
            font-size: 14/3.75+vw;
            vertical-align: middle;
        }
    }
</style>
